<?php
include_once '../inc/config.inc.php';
include_once '../inc/mysqli.inc.php';
include_once '../inc/tool.inc.php';
if(!isset($_GET['id'])||!is_numeric($_GET['id'])||$_GET['id']<1){
    skip('index.php','error','id参数不合法！ ');
}
$link=connect();
$memberid=is_login($link);
$queryt="select *from content where id={$_GET['id']}";
$resultt=execute($link,$queryt);
if(mysqli_num_rows($resultt)!=1){
    skip('index.php','error','id参数不合法！ ');
}
$datat=mysqli_fetch_assoc($resultt);
$datat=dehtml($datat);
$datat['title']=tonl2br($datat['title']);
$datat['content']=tonl2br($datat['content']);
$queryt="update content set times=times+1 where id={$_GET['id']}";
execute($link,$queryt);
$datat['times']++;

$queryc="select *from childModule where id={$datat['cmid']}";
$resultc=execute($link,$queryc);
$datac=mysqli_fetch_assoc($resultc);
$datac=dehtml($datac);
$queryf="select *from fatherModule where id={$datac['referid']}";
$dataf=mysqli_fetch_assoc(execute($link,$queryf));
$dataf=dehtml($dataf);
$queryr="select *from reply where contentid={$_GET['id']}";
$resultr=execute($link,$queryr);
$count_all=mysqli_num_rows($resultr);
//var_dump($dataf); exit;

if(!isset($_GET['page'])||!is_numeric($_GET['page'])||$_GET['page']<1||empty($_GET['page'])){
    $_GET['page']=1;
}
$page_cur=3; 
$fl=($_GET['page']-1)*$page_cur+1;
//var_dump($_GET['page']);exit;

$template='内容展示页';
include_once 'inc/header.inc.php';
?>


<div class="showmain">
            <div class="wrap">
                <h2 class="top_dir">
                    <a href="index.php">首页</a>&nbsp;&gt;
                    <a href='<?php echo "parentList.php?id={$dataf['id']}";?>' ><?php echo "{$dataf['moduleName']}";?></a>&nbsp;&gt;
                    <a href='<?php echo "childList.php?id={$datac['id']}";?>' ><?php echo "{$datac['moduleName']}";?></a>&nbsp;&gt;
                    <span>帖子内容</span>
                </h2>
                <div class="page_index clear-float">
                    <input type="button" onclick="window.location.href='reply.php?id=<?php echo $_GET['id'];?>'" class="btn_link fr" value="回复"/>
                    <div class="pages fl">
                    <?php $datas=pages($count_all,$page_cur);echo $datas['html'] ?>
                    <!-- 跳转页函数 -->
                    </div>
                </div>
                
                <div class="group clear-float">
                    <div class="fl">
                        <?php
                        $querym="select *from member where id={$datat['memberid']}";
                        $resultm=execute($link,$querym);
                        $datam=mysqli_fetch_assoc($resultm);
                         if(empty($datam['photo'])){
                            echo " <a href='#'><img width='120' height='120' src='/Project_bbs/img/三儿.jpg'> </a>";
                        }else{
                            echo " <a href='#'><img width='120' height='120' src='{$datam['photo']}'> </a>";
                        }                       
                        $datam=dehtml($datam);
                        echo "<div class='name'>{$datam['name']}</div>"; 
                         ?>
                    </div>
                    
                    <div class="fr">
                        <div class="part">
                            <div class="edge">
                                <div class="begin clear-float">
                                    <div class="theme fl"><?php echo $datat['title'];?></div>
                                    <div class="count fr">阅读： <span><?php echo $datat['times'];?></span> | 回复： <span><?php echo $count_all;?></span></div>
                                </div>
                                <div class="detail clear-float">
                                    <div class="fl">发布于：<?php echo $datat['time'];?></div>
                                    <div class="fr"><span><?php echo $datam['name'];?> | 楼主</span></div>
                                </div>
                                <div class="text"><?php echo $datat['content'];?></div>
                            </div>
                        </div>  
                    </div>
                </div>



                
                <?php
                if($count_all){
                    $queryr="select *from reply where contentid={$_GET['id']} limit {$datas['limit']}"; 
                    $resultr=execute($link,$queryr);        
                    while($datar=mysqli_fetch_assoc($resultr)){
                        $datar=dehtml($datar);
                        $datar=tonl2br($datar);
                        $fl++;
                        $querym="select *from member where id={$datar['memberid']}";
                        $resultm=execute($link,$querym);  
                        $datam=mysqli_fetch_assoc($resultm);
                        echo "<div class='group clear-float'>";
                        echo "<div class='fl'>";
                        if(empty($datam['photo'])){
                            echo " <a href='#'><img width='120' height='120' src='/Project_bbs/img/三儿.jpg'> </a>";
                        }else{
                            echo " <a href='#'><img width='120' height='120' src='{$datam['photo']}'> </a>";
                        } 
                        $datam=dehtml($datam);
                        echo "<div class='name'>{$datam['name']}</div>"; 
                        echo "</div>";
$htmlr=<<< A
                        <div class="fr">
                            <div class="part">
                                <div class="edge">
                                    <div class="detail clear-float">
                                        <div class="fl">回复时间：{$datar['time']}</div>
                                        <div class="fr">{$fl}楼 |<a href="quote.php?id={$datar['id']}"> 引用</a></div>
                                    </div>
                                    <div class="text">{$datar['content']}</div>
                                </div>
                            </div>  
                        </div>
A;

                        if(!$datar['quoteid']){
                           echo $htmlr; 
                        }else{    
                            $query="select count(*) from reply where id<={$datar['quoteid']} and contentid={$datat['id']}";
                            $result=execute($link,$query);
                            $flq=mysqli_fetch_row($result)[0]+1;
                            
                            $queryq="select *from reply where id={$datar['quoteid']}";
                            $resultq=execute($link,$queryq);
                            $dataq=mysqli_fetch_assoc($resultq);
                            $dataq=dehtml($dataq);
                            $dataq=tonl2br($dataq);
                            $querymq="select *from member where id={$dataq['memberid']}";
                            $resultmq=execute($link,$querymq);
                            $datamq=mysqli_fetch_assoc($resultmq);
                            $datamq=dehtml($datamq);

                            
$htmlq=<<< B
                            <div class="fr">
                                <div class="part">
                                    <div class="edge">
                                        <div class="detail clear-float">
                                            <div class="fl">回复时间：{$datar['time']}</div>
                                            <div class="fr">{$fl}楼 |<a href="quote.php?id={$datar['id']}"> 引用</a></div>
                                        </div>
                                        <div class="cite">
                                                <div class="exp">引用 {$flq}楼 {$datamq['name']}发表的：</div>
                                                <div class="link">{$dataq['content']}</div>
                                            </div>
                                        <div class="text">{$datar['content']}</div>
                                    </div>
                                </div>  
                            </div>
B;
                            echo $htmlq; 
                        }
                        
                        echo "</div>";
                        }  
                    }                       
                    ?>
                               

                <div class="page_index clear-float">
                    <input type="button" onclick="window.location.href='reply.php?id=<?php echo $_GET['id'];?>'" class="btn_link fr" value="回复"/>
                    <div class="pages fl">
                    <?php echo $datas['html'] ?>
                    </div>
                </div>
            </div>
        </div>


<?php
include_once 'inc/footer.inc.php';
?>